<?php

namespace JsonLowCode\UI;

use JsonLowCode\Schema;
use JsonLowCode\Traits\Props\HasExtra;
use JsonLowCode\Traits\Props\HasSubTitle;
use JsonLowCode\Traits\Props\HasTitle;
use JsonLowCode\Traits\Slots\HasSlotAvatar;
use JsonLowCode\Traits\Slots\HasSlotExtra;
use JsonLowCode\Traits\Slots\HasSlotFooter;
use JsonLowCode\Traits\Slots\HasSlotHeader;
use JsonLowCode\Traits\Slots\HasSlotSubTitle;
use JsonLowCode\Traits\Slots\HasSlotTitle;

/**
 * PageHeader组件
 * @method static PageHeader make(string $title, string $subtitle = "", mixed $children = null) PageHeader组件
 */
class PageHeader extends Schema
{
    protected string $componentName = "NPageHeader";

    use HasTitle, HasSubTitle, HasExtra;

    use HasSlotHeader, HasSlotTitle, HasSlotFooter, HasSlotExtra, HasSlotSubTitle, HasSlotAvatar;

    /**
     * @param string $title
     * @param string $subtitle
     * @param mixed|null $children
     */
    public function __construct(string $title, string $subtitle = "", mixed $children = null)
    {
        parent::__construct();
        $this->title($title)->children($children);
        if ($subtitle){
            $this->subtitle($subtitle);
        }
    }

    /**
     * 启用点击返回事件
     * @param string $value
     * @return $this
     */
    public function onBack(string $value = "()=>{ FastNaive.\$router.back() }"): static
    {
        return $this->events("onBack",$value);
    }

    /**
     * 设置 slot avatar 内容
     * @param mixed $value
     * @return $this
     */
    public function slotBack(mixed $value = null): static
    {
        return $this->slot('avatar', $value);
    }
}
